<template>
    <view class="pub_page pub_page_bg pub_wallet_withdraw pub_header_padding">
        <pub-head headerName="wallet_withdraw" :headerConfig="headerConfig" @headerBack="headerBack"></pub-head>
        <pub-dialog v-show="dialogShow" dialogName="wallet_withdraw" :dialogConfig="dialogConfig"
            @dialogBack="dialogBack"></pub-dialog>
        <div class="pub_page_scroll page_box">
            <div class="msg_div">
                <div class="p">提现到账时间1工作日以内,手续费单笔 {{ withdrawConfig.pro }} U</div>
                <!-- <div class="p">注: 最低提现 {{ withdrawConfig.min }} U</div> -->
            </div>
            <div class="pub_inputs">
                <div class="abox">
                    <div class="ali">
                        <div class="atitle">提现数量</div>
                        <input class="ainput" v-model="money" type="number" placeholder="请输入提现数量" />
                    </div>
                    <div class="ali">
                        <div class="atitle">支付密码</div>
                        <input class="ainput" v-model="payPassword" type="password" placeholder="请输入" maxlength="6">
                    </div>
                    <div class="ali">
                        <div class="atitle">钱包地址</div>
                        <textarea class="atextarea" v-model="address" placeholder="请输入钱包地址"></textarea>
                    </div>
                </div>
            </div>
            <br>
            <br>
            <div class="pub_btn" @click="walletDeal('to_withdraw')">发起提现申请</div>
            <br>
            <br>
        </div>
    </view>
</template>

<script>
export default {
    data() {
        return {
            pagescrollTop: 0,
            headerConfig: {
                title: '提现绑定',//标题栏内容
                left_type: 3,
                right_type: 1,//右侧区域类型  0不出现  1文字  2图片
                right_content: '提现记录',//右侧内容  right_type为1时文字内容 为2时图片链接
            },

            dialogShow: false,
            dialogType: '',
            dialogData: '',
            dialogConfig: {
                // title: 'demo',//标题栏内容
                content: '',
            },

            withdrawConfig: {
                min: 0,
                pro: 0
            },


            address: "",
            money: "",
            payPassword: ""
        };
    },
    watch: {
        'money': {
            handler() {
                this.money = this.money.replace(/^(0+)|[^\d]+/g, '');
            },
            immediate: true,
            deep: true
        },
    },
    onLoad() {
        this.getWithdrawConfig();
    },
    onPageScroll(res) {
        this.pagescrollTop = res.scrollTop;
    },
    methods: {
        headerBack(data) {
            if (data.name == 'wallet_withdraw' && data.type == 'right') {
                this.$comFun.openWin('/pages/mine/usdt_log', { openType: 'withdraw' });
            }
        },
        dialogBack(data) {
            // console.log(data);
            this.dialogShow = false;
            if (data.name == 'wallet_withdraw' && data.key == 1) {
                let obj = {
                    'walletWithdraw': 'sure_withdraw',
                }
                this.walletDeal(obj[this.dialogType])
            }
        },
        // 获取提现配置
        async getWithdrawConfig() {
            let configRes = await getApp().getConfigList();
            this.withdrawConfig.min = 0;
            this.withdrawConfig.pro = configRes.usdWithdrawalsPro;
        },
        async walletDeal(type, info, key) {
            switch (type) {
                case 'to_withdraw':
                    if (this.money == '' || !this.$comFun.ValidateNum(this.money)) {
                        this.$comFun.toast('请输入正确的提现数量');
                        return;
                    }
                    if (this.payPassword == '') {
                        this.$comFun.toast('请输入支付密码');
                        return;
                    }
                    if (this.address == '') {
                        this.$comFun.toast('请输入钱包地址');
                        return;
                    }
                    this.dialogType = 'walletWithdraw';
                    this.dialogShow = true;
                    this.dialogConfig = {
                        content: '是否确定提现？',
                    };
                    break;
                case 'sure_withdraw':
                    this.$comFun.openLoading();
                    const res_2 = await this.$request.post('user/applyWithdrawal', {
                        address: this.address,
                        money: this.money,
                        payPassword: this.payPassword,
                    });
                    this.$comFun.closeLoading();
                    this.$comFun.toast(res_2.message);
                    if (res_2.code == 200) {
                        this.address = '';
                        this.money = '';
                        this.payPassword = '';
                    }
                    break;
            }
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/mine.scss";
</style>
